using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace Acms.WebControls
{
    [PersistChildren(true)]
    [ParseChildren(false)]
    [ToolboxData("<{0}:RoundedBox runat=server></{0}:RoundedBox>")]
    [Designer(typeof(RoundedBoxDesigner))]
    public class RoundedBox : WebControl
    {
        protected override void Render(HtmlTextWriter writer)
        {
            if (this.CssClass != null)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
            }

            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            if (!BackColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(BackColor));
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "roundedTop");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r1");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r2");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r3");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r4");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            writer.RenderEndTag();

            RenderContents(writer);

            if (!BackColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(BackColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "roundedBottom");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r4");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r3");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r2");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            if (!ForeColor.IsEmpty)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, System.Drawing.ColorTranslator.ToHtml(ForeColor));
            }
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "r1");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            writer.RenderEndTag();

            writer.RenderEndTag();

            writer.RenderEndTag();

        }
    }

    public class RoundedBoxDesigner : ContainerControlDesigner
    {
        public override string FrameCaption
        {
            get { return "Acms Rounded Box"; }
        }

        private Style _Style;
        public override Style FrameStyle
        {
            get
            {
                if (_Style == null)
                {
                    _Style = new Style();
                    _Style.Width = Unit.Percentage(90);
                    _Style.Font.Name = "Verdana";
                    _Style.Font.Size = new FontUnit("Small");
                    _Style.BackColor = Color.LightGray;
                    _Style.ForeColor = Color.Black;
                }
                return _Style;
            }
        }
    }

}
